<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\order\Order as OrderModel;
use app\api\model\order\OrderMaster as OrderMasterModel;
use app\api\model\hospital\Hospital as HospitalModel;
use think\Db;

/**
 * 患者接口
 */
class Patient extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->loadlang('order');
    }
    
    /**
     * 报告列表
     */
    public function reportList()
    {
        $hospital_id = $this->request->post('hospital_id');
        $title = $this->request->post('title');
        $between = $this->request->post('between/a');
        $page = $this->request->post('page', 1);
        $limit = $this->request->post('limit', 10);

        $where = [
            'userphone' => $this->auth->mobile,
            'status'=>30,
            'report_status'=>30
        ];

        if ($hospital_id) {
            $where['order.hospital_id'] = $hospital_id;
        }
        if ($between && count($between) == 2) {
            $where['order.overtime'] = ['between', [strtotime($between[0] . ' 00:00:00'), strtotime($between[1] . ' 23:59:59')]];
        }
        // if($title){
        //     $where['order_goods.title'] = ['like', '%'.$title.'%'];
        // }


        $data = OrderMasterModel::alias('order')->field("order.*")
                        ->where($where)
                        ->with(['ordergoods', 'orderTube','hospital'])
                        ->order("order.overtime desc")
                        ->paginate($limit, false, ['page' => $page]);
        $this->success('', $data);

    }

}